home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbpdem / cancprt.frm < prev    next >
Text File  |  1995-12-05  |  5KB  |  173 lines

  1. VERSION 2.00
  2. Begin Form PrinterACTION 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Printer ACTION"
  6.    ClientHeight    =   1965
  7.    ClientLeft      =   2550
  8.    ClientTop       =   2760
  9.    ClientWidth     =   4050
  10.    Height          =   2370
  11.    Left            =   2490
  12.    LinkMode        =   1  'Source
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   1965
  17.    ScaleWidth      =   4050
  18.    Top             =   2415
  19.    Width           =   4170
  20.    Begin CommandButton CancelButton 
  21.       Caption         =   "Cancel"
  22.       Height          =   375
  23.       Left            =   2280
  24.       TabIndex        =   1
  25.       Top             =   1440
  26.       Width           =   1455
  27.    End
  28.    Begin PictureBox Picture1 
  29.       BackColor       =   &H00FFFFFF&
  30.       BorderStyle     =   0  'None
  31.       Height          =   735
  32.       Left            =   120
  33.       Picture         =   CANCPRT.FRX:0000
  34.       ScaleHeight     =   735
  35.       ScaleWidth      =   615
  36.       TabIndex        =   0
  37.       Top             =   240
  38.       Width           =   615
  39.    End
  40.    Begin Label PageNumber 
  41.       ForeColor       =   &H00FF0000&
  42.       Height          =   375
  43.       Left            =   240
  44.       TabIndex        =   4
  45.       Top             =   1440
  46.       Width           =   1935
  47.    End
  48.    Begin Label DocumetName 
  49.       Alignment       =   2  'Center
  50.       FontBold        =   -1  'True
  51.       FontItalic      =   0   'False
  52.       FontName        =   "MS Sans Serif"
  53.       FontSize        =   9.75
  54.       FontStrikethru  =   0   'False
  55.       FontUnderline   =   0   'False
  56.       ForeColor       =   &H000000FF&
  57.       Height          =   375
  58.       Left            =   960
  59.       TabIndex        =   3
  60.       Top             =   840
  61.       Width           =   3015
  62.    End
  63.    Begin Label PrinterHEADER 
  64.       Alignment       =   2  'Center
  65.       BackColor       =   &H00FFFFFF&
  66.       Caption         =   "Printing in Progress"
  67.       FontBold        =   -1  'True
  68.       FontItalic      =   0   'False
  69.       FontName        =   "MS Sans Serif"
  70.       FontSize        =   12
  71.       FontStrikethru  =   0   'False
  72.       FontUnderline   =   0   'False
  73.       ForeColor       =   &H000000FF&
  74.       Height          =   615
  75.       Left            =   840
  76.       TabIndex        =   2
  77.       Top             =   120
  78.       Width           =   3135
  79.    End
  80. End
  81. Sub CancelButton_Click ()
  82.     pABORT = True
  83.     Beep
  84.  
  85. End Sub
  86.  
  87. Sub Command1_Click ()
  88.         pABORT = True
  89. End Sub
  90.  
  91. Sub Form_Load ()
  92.  
  93. ' Please note this DEMO only allows printing of TEXT Documents in the
  94. ' Current default sub-directory...
  95.  
  96. ' This routine will print a file to the DEFAULT printer
  97. ' Allowing the user to CANCEL the job. The routine also offers
  98. ' proper page breaks to occur in the output.
  99.  
  100.  
  101. Dim PrintLine As String, HeaderLine As String
  102. Dim PageSize As Integer, LineSpace As Integer, LinesPerPage As Integer
  103. Dim LineLength As Integer, CurrentLine As Integer
  104.  
  105. Dim PageInfo As TextMetric
  106.     printerACTION.Show
  107.     DocumetName.Caption = UCase$(DocName)
  108.     printerACTION.Refresh
  109.  
  110.  
  111.     pABORT = False              ' Set ABORT flag to FALSE
  112.  
  113.     screen.mousepointer = NORMAL
  114.     code = GetTextMetrics(Printer.hdc, PageInfo) ' Get Printer Page Information
  115.  
  116. ' Calc the available space
  117.     LineSpace = PageInfo.tmHeight + PageInfo.tmExternalLeading
  118.     PageSize = GetDeviceCaps(Printer.hdc, VERTRES)
  119.  
  120.     LinesPerPage = Int(PageSize / (LineSpace - 1)) - 1
  121.  
  122.     HeaderLine = "                Print Routine Ver 1.0  EJO      Page: "
  123.  
  124. ' Open the TEXT File to print
  125.     
  126.     Open DocName For Input As #1
  127.     
  128.     CurrentLine = 3
  129.     printerACTION.PageNumber.Caption = "Printing Page : 1"
  130.     printerACTION.Refresh
  131.  
  132.     Printer.Print HeaderLine + "1" + Chr$(13) + Chr$(10)
  133.  
  134.     Do While Not EOF(1) And DoEvents()
  135.     
  136. ' Allow the User to ABORT
  137.         code = SetActiveWindow(printerACTION.hdc)
  138.     
  139.         Line Input #1, PrintLine
  140.         Printer.Print PrintLine
  141.         CurrentLine = CurrentLine + 1  ' increment the Current Line counter
  142.         If CurrentLine > LinesPerPage Then
  143.             CurrentLine = 3
  144.         
  145.     
  146.             If pABORT = True Then  ' Printing is ABORTED
  147.                 printerACTION.PrinterHEADER.Caption = "Printing has been ABORTED"
  148.                 printerACTION.Refresh
  149.                 delay_it (5)       ' Allow message to be read
  150.                 Exit Do
  151.             Else
  152.                 Printer.NewPage
  153.                 printerACTION.PageNumber.Caption = "Printing Page : " + Str$(Printer.page)
  154.                 printerACTION.Refresh
  155.  
  156. ' Any Headers Should be Printed Here
  157.  
  158.                 Printer.Print HeaderLine + LTrim$(Str$(Printer.page)) + Chr$(13) + Chr$(10)
  159.         
  160.             End If
  161.     
  162.         End If
  163.     Loop
  164.     
  165. ' Housekeeping for end of Print JOB
  166.  
  167.     Printer.NewPage
  168.     Printer.EndDoc      ' END of the Printing job
  169.     Close #1
  170.  
  171. End Sub
  172.  
  173.